package com.ruoyi.exen.common.handler;

import com.ruoyi.exen.common.utils.weChat.SendWeChatMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 企业微信发送消息处理器
 * @author EMY2305005
 */
@Component
public class WeChatHandler implements HandlerInterceptor {


    @Autowired
    private SendWeChatMessage sendWeChatMessage;

    /**\
     *
     * postHandle方法：此方法将在controller执行之后执行，但是视图还没有解析，可向ModelAndView中添加数据(前后端不分离的)。
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        String method = request.getMethod();
        if (!"POST".equals(method)) {
            return;
        }
        Boolean result = (Boolean) request.getAttribute("result");
        if(!result){
            return;
        }
        String content = (String) request.getAttribute("content");
        sendWeChatMessage.sendWeChatMessageToParty("138",content);
    }


    

}
